home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / share / ewl / examples / ewl_freebox_test.c < prev    next >
C/C++ Source or Header  |  2006-01-09  |  6KB  |  217 lines

  1. #include "ewl_test.h"
  2. #include <stdlib.h>
  3.  
  4. static Ewl_Widget *fb_button;
  5. static Ewl_Widget *sort_fb;
  6.  
  7. static void
  8. ewl_freebox_cb_icon_change(Ewl_Widget *w __UNUSED__, void *ev __UNUSED__, 
  9.                                 void *data)
  10. {
  11.     Ewl_Freebox *fb;
  12.  
  13.     fb = data;
  14.     ewl_freebox_resort(EWL_FREEBOX(fb));
  15. }
  16.  
  17. static int
  18. ewl_freebox_cb_compare(Ewl_Widget *a, Ewl_Widget *b)
  19. {
  20.     const char *a_txt, *b_txt;
  21.  
  22.     a_txt = ewl_icon_label_get(EWL_ICON(a));
  23.     b_txt = ewl_icon_label_get(EWL_ICON(b));
  24.  
  25.     return strcmp(a_txt, b_txt);
  26. }
  27.  
  28. static void
  29. ewl_freebox_cb_add(Ewl_Widget *w __UNUSED__, void *ev __UNUSED__, 
  30.                         void *data)
  31. {
  32.     Ewl_Freebox *fb;
  33.     Ewl_Widget *i;
  34.     int t;
  35.  
  36.     struct 
  37.     { 
  38.         char *name;
  39.         char *path;
  40.     } files[] = {
  41.         {"Draw", PACKAGE_DATA_DIR "/images/Draw.png"},
  42.         {"End", PACKAGE_DATA_DIR "/images/End.png"},
  43.         {"Card", PACKAGE_DATA_DIR "/images/NewBCard.png"},
  44.         {"Open", PACKAGE_DATA_DIR "/images/Open.png"},
  45.         {"Package", PACKAGE_DATA_DIR "/images/Package.png"},
  46.         {"World", PACKAGE_DATA_DIR "/images/World.png"},
  47.         {NULL, NULL}
  48.     };
  49.  
  50.     fb = data;
  51.  
  52.     for (t = 0; files[t].name != NULL; t++)
  53.     {
  54.         long width, height;
  55.  
  56.         width = (rand() % 30) + 30;
  57.         height = (rand() % 30) + 30;
  58.  
  59.         i = ewl_icon_new();
  60.         ewl_container_child_append(EWL_CONTAINER(fb), i);
  61.         ewl_icon_label_set(EWL_ICON(i), files[t].name);
  62.         ewl_icon_image_set(EWL_ICON(i), files[t].path, NULL);
  63.         ewl_object_fill_policy_set(EWL_OBJECT(i),
  64.                         EWL_FLAG_FILL_FILL);
  65.         ewl_object_minimum_size_set(EWL_OBJECT(i), (int)width,
  66.                             (int)height);
  67.  
  68.         if (fb == sort_fb)
  69.         {
  70.             ewl_icon_editable_set(EWL_ICON(i), TRUE);
  71.             ewl_callback_append(i, EWL_CALLBACK_VALUE_CHANGED,
  72.                     ewl_freebox_cb_icon_change, fb);
  73.         }
  74.         ewl_widget_show(i);
  75.     }
  76. }
  77.  
  78. static void 
  79. cb_destroy_win(Ewl_Widget *w, void *ev __UNUSED__, void *data __UNUSED__)
  80. {
  81.     ewl_widget_destroy(w);
  82.     ewl_callback_append(fb_button, EWL_CALLBACK_CLICKED,
  83.                 __create_freebox_test_window, NULL);
  84. }
  85.  
  86. void
  87. __create_freebox_test_window(Ewl_Widget *w, void *ev __UNUSED__,
  88.                     void *data __UNUSED__)
  89. {
  90.     Ewl_Widget *win, *box, *hbox, *fb, *pane, *o;
  91.  
  92.     fb_button = w;
  93.  
  94.     srand(time(NULL));
  95.  
  96.     win = ewl_window_new();
  97.     ewl_window_title_set(EWL_WINDOW(win), "Freebox Test");
  98.     ewl_window_name_set(EWL_WINDOW(win), "EWL Test Application");
  99.     ewl_window_class_set(EWL_WINDOW(win), "EFL Test Application");
  100.     ewl_object_size_request(EWL_OBJECT(win), 400, 600);
  101.  
  102.     if (w)
  103.     {
  104.         ewl_callback_del(w, EWL_CALLBACK_CLICKED,
  105.                     __create_freebox_test_window);
  106.         ewl_callback_append(win, EWL_CALLBACK_DELETE_WINDOW,
  107.                     cb_destroy_win, NULL);
  108.     }
  109.     else
  110.         ewl_callback_append(win, EWL_CALLBACK_DELETE_WINDOW,
  111.                     __close_main_window, NULL);
  112.     ewl_widget_show(win);
  113.  
  114.     box = ewl_vbox_new();
  115.     ewl_container_child_append(EWL_CONTAINER(win), box);
  116.     ewl_widget_show(box);
  117.  
  118.     /* the manual box */
  119.     o = ewl_label_new();
  120.     ewl_label_text_set(EWL_LABEL(o), "Manual Placement");
  121.     ewl_object_fill_policy_set(EWL_OBJECT(o), EWL_FLAG_FILL_SHRINK);
  122.     ewl_container_child_append(EWL_CONTAINER(box), o);
  123.     ewl_widget_show(o);
  124.  
  125.     hbox = ewl_hbox_new();
  126.     ewl_container_child_append(EWL_CONTAINER(box), hbox);
  127.     ewl_object_fill_policy_set(EWL_OBJECT(hbox), EWL_FLAG_FILL_FILL);
  128.     ewl_object_alignment_set(EWL_OBJECT(hbox), EWL_FLAG_ALIGN_TOP);
  129.     ewl_widget_show(hbox);
  130.  
  131.     fb = ewl_freebox_new();
  132.  
  133.     o = ewl_button_new();
  134.     ewl_button_label_set(EWL_BUTTON(o), "Add items");
  135.     ewl_object_fill_policy_set(EWL_OBJECT(o), EWL_FLAG_FILL_SHRINK);
  136.     ewl_object_alignment_set(EWL_OBJECT(o), EWL_FLAG_ALIGN_TOP);
  137.     ewl_container_child_append(EWL_CONTAINER(hbox), o);
  138.     ewl_callback_append(o, EWL_CALLBACK_CLICKED, 
  139.                 ewl_freebox_cb_add, fb);
  140.     ewl_widget_show(o);
  141.  
  142.     pane = ewl_scrollpane_new();
  143.     ewl_container_child_append(EWL_CONTAINER(hbox), pane);
  144.     ewl_widget_show(pane);
  145.  
  146.     ewl_freebox_layout_type_set(EWL_FREEBOX(fb),
  147.                     EWL_FREEBOX_LAYOUT_MANUAL);
  148.     ewl_container_child_append(EWL_CONTAINER(pane), fb);
  149.     ewl_widget_show(fb);
  150.  
  151.     /* the auto box */
  152.     o = ewl_label_new();
  153.     ewl_label_text_set(EWL_LABEL(o), "Auto Placement");
  154.     ewl_object_fill_policy_set(EWL_OBJECT(o), EWL_FLAG_FILL_SHRINK);
  155.     ewl_container_child_append(EWL_CONTAINER(box), o);
  156.     ewl_widget_show(o);
  157.  
  158.     hbox = ewl_hbox_new();
  159.     ewl_container_child_append(EWL_CONTAINER(box), hbox);
  160.     ewl_widget_show(hbox);
  161.  
  162.     fb = ewl_freebox_new();
  163.  
  164.     o = ewl_button_new();
  165.     ewl_button_label_set(EWL_BUTTON(o), "Add items");
  166.     ewl_object_fill_policy_set(EWL_OBJECT(o), EWL_FLAG_FILL_SHRINK);
  167.     ewl_object_alignment_set(EWL_OBJECT(o), EWL_FLAG_ALIGN_TOP);
  168.     ewl_container_child_append(EWL_CONTAINER(hbox), o);
  169.     ewl_callback_append(o, EWL_CALLBACK_CLICKED, 
  170.                 ewl_freebox_cb_add, fb);
  171.     ewl_widget_show(o);
  172.  
  173.     pane = ewl_scrollpane_new();
  174.     ewl_container_child_append(EWL_CONTAINER(hbox), pane);
  175.     ewl_widget_show(pane);
  176.  
  177.     ewl_freebox_layout_type_set(EWL_FREEBOX(fb),
  178.                     EWL_FREEBOX_LAYOUT_AUTO);
  179.     ewl_container_child_append(EWL_CONTAINER(pane), fb);
  180.     ewl_widget_show(fb);
  181.  
  182.     /* the comparator box */
  183.     o = ewl_label_new();
  184.     ewl_label_text_set(EWL_LABEL(o), "Comparator Placement (by name)");
  185.     ewl_object_fill_policy_set(EWL_OBJECT(o), EWL_FLAG_FILL_SHRINK);
  186.     ewl_container_child_append(EWL_CONTAINER(box), o);
  187.     ewl_widget_show(o);
  188.  
  189.     hbox = ewl_hbox_new();
  190.     ewl_container_child_append(EWL_CONTAINER(box), hbox);
  191.     ewl_widget_show(hbox);
  192.  
  193.     fb = ewl_freebox_new();
  194.  
  195.     o = ewl_button_new();
  196.     ewl_button_label_set(EWL_BUTTON(o), "Add items");
  197.     ewl_object_fill_policy_set(EWL_OBJECT(o), EWL_FLAG_FILL_SHRINK);
  198.     ewl_object_alignment_set(EWL_OBJECT(o), EWL_FLAG_ALIGN_TOP);
  199.     ewl_container_child_append(EWL_CONTAINER(hbox), o);
  200.     ewl_callback_append(o, EWL_CALLBACK_CLICKED, 
  201.                 ewl_freebox_cb_add, fb);
  202.     ewl_widget_show(o);
  203.  
  204.     pane = ewl_scrollpane_new();
  205.     ewl_container_child_append(EWL_CONTAINER(hbox), pane);
  206.     ewl_widget_show(pane);
  207.  
  208.     ewl_freebox_layout_type_set(EWL_FREEBOX(fb),
  209.                     EWL_FREEBOX_LAYOUT_COMPARATOR);
  210.     ewl_freebox_comparator_set(EWL_FREEBOX(fb), 
  211.                     ewl_freebox_cb_compare);
  212.     ewl_container_child_append(EWL_CONTAINER(pane), fb);
  213.     ewl_widget_show(fb);
  214.     sort_fb = fb;
  215. }
  216.  
  217.